package com.mxx.common.data.utils;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/**
 * @Author itzgyw
 * @Date 2020-01-09
 * @Time 11:47
 * @Description:
 */
public class SortPaged implements Pageable {
    public final static SortPaged unSort = new SortPaged(Sort.unsorted());
    public final static SortPaged nullSort = new SortPaged(null);
    private Sort sort;

    SortPaged(Sort sort) {
        if (sort != null) {
            this.sort = sort;
        } else {
            this.sort = Sort.unsorted();
        }
    }

    public static SortPaged create(Sort sort) {
        return new SortPaged(sort);
    }


    public boolean isPaged() {
        return false;
    }

    public Pageable previousOrFirst() {
        return this;
    }

    public Pageable next() {
        return this;
    }

    public boolean hasPrevious() {
        return false;
    }

    public Sort getSort() {
        return this.sort == null ? Sort.unsorted() : this.sort;
    }

    public int getPageSize() {
        throw new UnsupportedOperationException();
    }

    public int getPageNumber() {
        throw new UnsupportedOperationException();
    }

    public long getOffset() {
        throw new UnsupportedOperationException();
    }

    public Pageable first() {
        return this;
    }
}
